package com.example.orderflow.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.orderflow.entity.enums.PageSize;
import com.example.orderflow.entity.query.ApprovalProcessTestQuery;
import com.example.orderflow.entity.po.ApprovalProcessTest;
import com.example.orderflow.entity.vo.PaginationResultVO;
import com.example.orderflow.entity.query.SimplePage;
import com.example.orderflow.mappers.ApprovalProcessTestMapper;
import com.example.orderflow.service.ApprovalProcessTestService;
import com.example.orderflow.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("approvalProcessTestService")
public class ApprovalProcessTestServiceImpl implements ApprovalProcessTestService {

	@Resource
	private ApprovalProcessTestMapper<ApprovalProcessTest, ApprovalProcessTestQuery> approvalProcessTestMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<ApprovalProcessTest> findListByParam(ApprovalProcessTestQuery param) {
		return this.approvalProcessTestMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(ApprovalProcessTestQuery param) {
		return this.approvalProcessTestMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<ApprovalProcessTest> findListByPage(ApprovalProcessTestQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<ApprovalProcessTest> list = this.findListByParam(param);
		PaginationResultVO<ApprovalProcessTest> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(ApprovalProcessTest bean) {
		return this.approvalProcessTestMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<ApprovalProcessTest> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalProcessTestMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<ApprovalProcessTest> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalProcessTestMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(ApprovalProcessTest bean, ApprovalProcessTestQuery param) {
		StringTools.checkParam(param);
		return this.approvalProcessTestMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(ApprovalProcessTestQuery param) {
		StringTools.checkParam(param);
		return this.approvalProcessTestMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public ApprovalProcessTest getApprovalProcessTestById(Integer id) {
		return this.approvalProcessTestMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateApprovalProcessTestById(ApprovalProcessTest bean, Integer id) {
		return this.approvalProcessTestMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteApprovalProcessTestById(Integer id) {
		return this.approvalProcessTestMapper.deleteById(id);
	}
}